package jm.algorithm.greedy;

import java.util.ArrayList;
import java.util.Arrays;

/**
 * @Description 加勒比海盗
 * @date 2022/5/20 15:06
 */
public class Pirate {
    public static void main(String[] args) {
        int[] weights = {3, 5, 4, 10, 7, 14, 2, 11};
        Arrays.sort(weights);
        int capacity = 30;
        int weight = 0;
        int count = 0;
        for (int i = 0; i < weights.length; i++) {
            int newWeight = weight + weights[i];
            if (newWeight > capacity){
                break;
            }else {
                count ++;
                weight = newWeight;
                System.out.println(weights[i]);
            }
        }
        System.out.println(count);
    }
}
